package com.bert.thymeleafgenerator.config;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;

/**
 * 配置模板，自动生成代码
 *
 */
public enum ThymeLeafConfig {
    /**
     *
     */
    INSTANCE;
    private TemplateEngine templateEngine;

    ThymeLeafConfig(){
        ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
        //路径
        resolver.setPrefix("templates/thymeleaf/");
        //后缀
        //resolver.setSuffix(".java");
        //设置模板模式、默认是HTML
        resolver.setTemplateMode("TEXT");
        templateEngine = new TemplateEngine();
        templateEngine.setTemplateResolver(resolver);
    }

    public static TemplateEngine getTemplateEngine(){
        return INSTANCE.templateEngine;
    }

    public static String getTemplateString(String templateFile, Context context){
        return getTemplateEngine().process(templateFile, context);
    }
}
